#pragma once
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#pragma pack(4)
typedef struct srvAddress
{
    uint32_t  ip;        //以网络字节序存放,sin_addr.s_addr
    short     port;      //以网络字节序存放
}srvAddress;
#pragma pack()

typedef struct list
{
    int fd;
    time_t last;
    void *comm;
    srvAddress addr;    
    struct list *next,*prev;
}list;

typedef struct ralist
{
    int  len;
    list *head;
}ralist;

typedef struct ralIterator
{
    int  len;
    int  index;
    list *next;
}ralIterator;



ralIterator *ralCreateIterator(ralist *ral);
ralIterator *ralRewindIterator(ralist *ral, ralIterator *it);
list *ralIteratorNext(ralIterator *it);
list *ralIteratorLoopNext(ralIterator *it);
void ralIteratorRelease(ralIterator *it);
void ralPrint(ralist *ral);
ralist *ralCreate(void);
void ralDelete(ralist *ral, list *l);
int ralRelease(ralist *ral);
list* ralFind(ralist *ral, srvAddress *addr);
list* ralAddHead(ralist *ral, int fd, void *comm, srvAddress *addr);
void ralReleaseAcquireAddress(char *buf);
char *ralAcquireAllAddress(ralist *ral);




